package com.example.asus.recyclerview;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Adapter;
import android.widget.LinearLayout;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {
private  RecyclerView rlvstu;
private ArrayList<Student>studentArrayList=new ArrayList<>();
private Stuadapter adapter;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       initstudentArryList();
       /*初始化adapter传值进去*/
       adapter=new Stuadapter(MainActivity.this,studentArrayList);
       rlvstu=findViewById(R.id.rlv_stu);
       rlvstu.setAdapter(adapter);
       /*创建布局管理器*/
        LinearLayoutManager manager=new LinearLayoutManager(MainActivity.this);
       rlvstu.setLayoutManager(manager);
    }

    private void initstudentArryList() {
        Student s1=new Student("张一","18001",18,R.drawable.one);
        Student s2=new Student("张二","18002",18,R.drawable.two);
        Student s3=new Student("张三","18003",18,R.drawable.three);
        Student s4=new Student("张四","18004",18,R.drawable.five);
        Student s5=new Student("张五","18005",18,R.drawable.frou);
        studentArrayList.add(s1);
        studentArrayList.add(s2);
        studentArrayList.add(s3);
        studentArrayList.add(s4);
        studentArrayList.add(s5);
    }
}
